package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Auther: zhaoss
 * @Date: 2023/5/4 - 05 - 04 - 19:00
 * @Description: com.sky.mapper
 * @version: 1.0
 */
@Mapper
public interface ShoppingCartMapper {
    /**
     * 根据条件查询购物车集合
     * @param shoppingCart
     * @return
     */
    ShoppingCart queryShoppingCar(ShoppingCart shoppingCart);

    /**
     * 新增购物车
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart (name, user_id, dish_id, setmeal_id, dish_flavor, number, amount, image, create_time)" +
            " values (#{name},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{image},#{createTime})")
    void add(ShoppingCart shoppingCart);

    /**
     * 更新商品数量
     *
     * @param shoppingCart
     */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumberById(ShoppingCart shoppingCart);

    /**
     * 根据用户id条件查询购物车集合
     * @param userId
     * @return
     */
    @Select("select * from shopping_cart where user_id = #{userId} order by create_time desc")
    List<ShoppingCart> getByUserId(Long userId);

    /**
     * 清空购物车
     * @param userId
     */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void deleteCar(Long userId);


    /**
     * 减一
     * @param
     */
    void deleteCarByid(ShoppingCart shoppingCart);


}
